package com.css.zfzx.sjcj.modules.drill.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.bpm.platform.base.response.RestResponse;
import com.css.bpm.platform.utils.PlatformPageUtils;
import com.css.zfzx.sjcj.modules.drill.Entity.QhY06Entity;
import com.css.zfzx.sjcj.modules.drill.service.QhY06Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author Li Helei
 * @date 2020-11-11
 */
@Slf4j
@RestController
@RequestMapping("/qh/qhY06")
public class QhY06Controller {
    @Autowired
    private QhY06Service qhY06Service;

    @GetMapping("/queryQhY06s")
    public RestResponse queryQhY06s(HttpServletRequest request, String drillId) {
        RestResponse response = null;
        try{
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            String sort= request.getParameter("sort");
            String order= request.getParameter("order");
            JSONObject jsonObject = qhY06Service.queryQhY06s(drillId, curPage, pageSize,sort,order);
            response = RestResponse.succeed(jsonObject);
        }catch (Exception e){
            String errorMessage = "查询失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }

    /*@PostMapping("/queryQhY06sNoPage")
    public RestResponse queryQhY06sNoPage(@RequestBody QhY06QueryParams queryParams) {
        RestResponse response = null;
        try{
            JSONObject jsonObject = qhY06Service.queryQhY06s(queryParams);
            response = RestResponse.succeed(jsonObject);
        }catch (Exception e){
            String errorMessage = "查询失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }*/

    @GetMapping("{id}")
    public RestResponse getQhY06(@PathVariable String id) {
        RestResponse response = null;
        try{
            QhY06Entity qhY06 = qhY06Service.getQhY06(id);
            response = RestResponse.succeed(qhY06);
        }catch (Exception e){
            String errorMessage = "获取失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }
    @PostMapping("/save")
    public RestResponse saveQhY06(@RequestBody QhY06Entity qhY06) {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try{
            qhY06Service.saveQhY06(qhY06);
            json.put("message", "新增成功!");
            response = RestResponse.succeed(json);
        }catch (Exception e){
            String errorMessage = "新增失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;

    }
    @PostMapping("/update")
    public RestResponse updateQhY06(@RequestBody QhY06Entity qhY06)  {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try{
            qhY06Service.updateQhY06(qhY06);
            json.put("message", "修改成功!");
            response = RestResponse.succeed(json);
        }catch (Exception e){
            String errorMessage = "修改失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }
    @PostMapping("/delete")
    public RestResponse deleteQhY06s(@RequestBody String ids) {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try{
            qhY06Service.deleteQhY06s(ids);
            json.put("message", "删除成功!");
            response = RestResponse.succeed(json);
        }catch (Exception e){
            String errorMessage = "删除失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }

    @PostMapping("/submit/{ids}")
    public RestResponse submitQhY06(@PathVariable String ids)  {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try{
            qhY06Service.submitQhY06(ids);
            json.put("message", "提交成功!");
            response = RestResponse.succeed(json);
        }catch (Exception e){
            String errorMessage = "提交失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }

}